package l1j.server.server.model;

import java.util.TimerTask;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;

public class L1EquipmentTimer extends TimerTask {

	private final L1PcInstance _pc;

	private final L1ItemInstance _item;

	private int _RemainingTime ;
	private final int Update = L1PcInventory.COL_REMAINING_TIME;
	public L1EquipmentTimer(final L1PcInstance pc, final L1ItemInstance item) {
		this._pc = pc;
		this._item = item;
		this._RemainingTime =this._item.getRemainingTime();
	}
	@Override
	public void run() {
		this._RemainingTime --;
		if (this._RemainingTime > 0) {
			this._item.setRemainingTime(this._RemainingTime);
			this._pc.getInventory().updateItem(this._item,this.Update);
		} else {
			this._pc.getInventory().setEquipped(this._item, false);
			this._pc.getInventory().removeItem(this._item, 1);
			this.cancel();
		}
	}
}
